<?php
/**
 * Created by PhpStorm.
 * User: xuyiping
 * Date: 2019/1/25
 * Time: 17:43
 */

include(__DIR__ . '/config.php');

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$exchange = 'router';
$queue = 'msgs';
$connection = new AMQPStreamConnection(HOST,PORT,USER,PASSWORD,VHOST);
$channel = $connection->channel();

$channel->queue_declare($queue,false,true,false,false);
$channel->exchange_declare($exchange,'direct',false,true,false);
$channel->queue_bind($queue,$exchange);

$messageBody = implode(' ',array_slice($argv,1));
//$message = new AMQPMessage($messageBody,array('content_type'=>'text/plain','delivery_mode'=>AMQPMessage::DELIVERY_MODE_PERSISTENT));
$message = new AMQPMessage($messageBody,array('content_type'=>'text/plain','delivery_mode'=>AMQPMessage::DELIVERY_MODE_PERSISTENT));
$channel->basic_publish($message,$exchange);
$channel->close();
$connection->close();